<!-- 报告公示 -->
<template>
  <div>
    <card>
      <p slot="title">
        <Row>
          <Col span="12" style="line-height:32px !important">报告公示
          </Col>
          <Col span="12" style="text-align: right">
          <Button type="primary">公示</Button>
          </Col>
        </Row>
      </p>
      <table width="100%" cellspacing="0" cellpadding="0" border="1" ref="print">
        <tr>
          <th colspan="4">报告公示表</th>
        </tr>
        <tr>
          <td width="25%">项目编号</td>
          <td colspan="3">
            {{info.Project_number}}
          </td>
        </tr>
        <tr>
          <td>项目名称</td>
          <td colspan="3">
            <Input v-model="info.Project_name" />
          </td>
        </tr>
        <tr>
          <td>建设单位</td>
          <td colspan="3">
            <Input v-model="info.Build_unit" />
          </td>
        </tr>
        <tr>
          <td>建设地点</td>
          <td colspan="3">
            <Input v-model="info.Build_address" />
          </td>
        </tr>
        <tr>
          <td>报告类型</td>
          <td colspan="3">
            <Input v-model="info.Report_type" />
          </td>
        </tr>
        <tr>
          <td width="25%">项目负责人</td>
          <td width="25%">
            {{info.Perject_leader}}
          </td>
          <td width="25%">项目组其他成员</td>
          <td width="25%">
            {{cyz}}
          </td>
        </tr>
        <tr>
          <td width="25%">审批部门</td>
          <td width="25%">

          </td>
          <td width="25%">公示时间</td>
          <td width="25%">
            {{this.$moment().format('YYYY-MM-DD')}}
          </td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">公式网址</td>
          <td colspan="3" class="left">网站名：wwww.baidu.com</td>
        </tr>
        <tr>
          <td colspan="3" class="left" width="75%">公示链接：<a href="wwww.baidu.com">wwww.baidu.com</a></td>
        </tr>
        <tr>
          <td width="25%">公示截图</td>
          <td colspan="3" width="75%">
            <Upload action="//jsonplaceholder.typicode.com/posts/">
              <Button>上传</Button>
            </Upload>
          </td>
        </tr>
        <tr>
          <td width="25%">公众参与报告</td>
          <td colspan="3" width="75%">
            <Upload action="//jsonplaceholder.typicode.com/posts/">
              <Button>上传</Button>
            </Upload>
          </td>
        </tr>
        <tr>
          <td rowspan="3" width="25%">是否收到投诉及意见</td>
          <td colspan="3" width="75%">
            <RadioGroup v-model="whether">
              <Radio label="yes">
                <span>是</span>
              </Radio>
              <Radio label="no">
                <span>否</span>
              </Radio>
            </RadioGroup>
          </td>
        </tr>
        <tr>
          <td colspan="3">
            <div style="width:99%;margin:auto;height:100%;">
              <Table border ref="selection" style="border: none" :columns="publicityQuestionsListOption" :data="publicityQuestionsList"></Table>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="3">
            <Button type="primary" @click="inputAdd('publicityQuestionsList')">添加</Button>
            <Button type="error">删除</Button>
          </td>
        </tr>
      </table>
      <Row type="flex" justify="space-between" class="topmargin">
        <Col span="4">
        <PrintButton v-if="flag" Url="print/printPublicShow" :Project_id="info.Id"></PrintButton>
        </Col>
        <Col span="4">
        <div style="float: right">
          <Button type="primary" @click="submit('save')">保存</Button>
          <Button type="primary" @click="submit('submit')">提交</Button>
        </div>
        </Col>
      </Row>
      <StepBar :status="8" />
    </card>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        flag: false,
        info: {},
        cyz: '',
        publicityQuestionsList: [],
        publicityQuestionsListOption: [{
            align: "center",
            width: 80,
            title: "序号",
            type: 'index'
          },
          {
            title: '投诉意见',
            key: 'Publicity_opinion',
            render: (h, {
              row,
              index
            }) => {
              return h("Input", {
                props: {
                  type: "text",
                  value: row.Publicity_opinion
                },
                on: {
                  "on-blur": val => {
                    this.publicityQuestionsList[index].Publicity_opinion = val.target.value;
                    this.publicityQuestionsList[index][
                      "Project_id"
                    ] = this.$route.query.Project_id || this.$route.query.id;
                  }
                }
              });
            }
          },
          {
            title: '解决结果',
            key: 'Revise_explain',
            render: (h, {
              row,
              index
            }) => {
              return h("Input", {
                props: {
                  type: "text",
                  value: row.Revise_explain
                },
                on: {
                  "on-blur": val => {
                    this.publicityQuestionsList[index].Revise_explain = val.target.value;
                    this.publicityQuestionsList[index][
                      "Project_id"
                    ] = this.$route.query.Project_id || this.$route.query.id;
                  }
                }
              });
            }
          }

        ],
        whether: 'no',
      }
    },
    created() {
      let query = this.$route.query
      this.query = query
      this.getProject(this.query.id)
      // 项目成员组
      this.findStaffs()
    },
    methods: {
      //点击添加意见
      inputAdd(type) {
        this[type].push({})
      },
      /* 获取当前创建项目 */
      getProject(id) {
        axios.get('/projectInformation/findProjectByID', {
          params: {
            id: id || this.$route.query.Project_id
          }
        }).then(res => {
          console.log(res)
          this.info = res.info
          this.publicityQuestionsList = res.publicityQuestionsList
          localStorage.projectType = this.info.Perject_type
          this.flag = true
        }).catch(err => {
          alert('请求崩溃1231')
        })
      },
      findStaffs() {
        axios.get('/audit/findStaffs', {
          params: {
            Project_id: this.query.id || this.query.Project_id
          }
        }).then(res => {
          console.log(res)
          if (res._STATUS == 1) {
            let cyz = []
            res.data.forEach((e, i) => {
              cyz.push(e['Staffs_name'])
            });
            this.cyz = cyz.join(',')
          }
        })
      },
      publicityQuestionsListFn() {
        let publicityQuestionsList = this.publicityQuestionsList
        axios.post('/publicityQuestions/saveOrUpdate', {
          publicityQuestionsList
        }).then(res => {

        }).catch(err => {
          alert('提交失败')
        })
      },
      // 保存 save / 提交 submit
      submit(type) {
        let info = this.info
        info.btn_way = type == 'save' ? 1 : 2
        info.Perject_type = type == 'save' ? 14 : 14

        this.publicityQuestionsListFn()
        axios.post('/projectInformation/saveOrUpdateProject', info).then((res) => {
          if (res._STATUS == 1) {
            let title = res._MESSAGE
            if (type == 'save') {
              this.$Modal.success({
                title,
              })
            } else {
              this.$router.push({
                name: "reportArchives",
                query: {
                  id: this.$route.query.id || this.$route.query.Project_id
                }
              })
            }
          } else {
            // 提示
            this.$Modal.error({
              title,
            })
          }
        }).catch(err => {
          alert('炸了')
        })

      }
    }
  }
</script>

<style scoped>

</style>